<template>
  <view class="order">
    <view class="info-box-crumb">
      <view @tap="change_crumb(index)" v-for="(item,index) in orderType" :class="orderTypeIndex==index?'active':''"><text>{{item.name}}</text></view>
    </view>
    <view class="order-list p-tb-25">
      <view class="item br-10 m-lr-30 m-b-30 p-lr-30 bg-w" v-for="(item,index) in courseList">
        <view class="xy-order-item br-10" @tap="$xyfun.to('/pages/user/order/course_detail?id='+item.id)">
          <view class="top">
            <view class="l">
              <text :class="'label '+item.type+'_ctype_color'">{{item.type_text}}</text>
              {{item.name}}
            </view>
            <view class="r">
              {{item.status_text}}
<!--              <view class="ts-20" style="color: rgb(255, 83, 53)">已退款</view>-->
            </view>
          </view>
          <view class="course">
            <view class="l">
              <image :src="$xyfun.image(item.image)" class="br-10" />
            </view>
            <view class="r">
              <view class="item-text ts-26 lh-40 m-b-10">{{$xyfun.timeFormat(item.service_start_time,'yyyy-mm-dd')}}
                <span class="tb" style="color:#95e8d0;margin-left: 15rpx;">{{$xyfun.timeFormat(item.service_start_time,'hh:MM')}}-{{$xyfun.timeFormat(item.service_end_time,'hh:MM')}}</span>
              </view>
              <view class="flex ali-cen m-t-10 m-b-10">
                <image class="avatar-40 m-r-10" :src="item.coach.avatar"></image>
                <text class="ts-24" style="color: #797979;">{{item.coach.nickname}}</text>
              </view>
              <view class="item-text ts-26 lh-40 m-b-10" v-if="item.course_timesec && item.course_timesec.place">{{item.course_timesec.place}}
                <span style="margin-left: 30rpx;" v-if="item.seat!==''">{{item.seat}}</span>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
	import { mapState } from 'vuex';
	import xyEmpty from '@/components/xy-empty';
	export default {
		components: {
			xyEmpty,
		},
		data() {
			return {
				isLoading:true,
				isEmpty: true,
				courseList: [],
				currentPage: 1,
				lastPage: 1,
				loadStatus: 'loadmore',

        orderTypeIndex: 0,
        orderType:[
          {name:'待支付',type:0},
          {name:'已完成',type:3},
        ],

        date : '',
        ctype_cn: '全部',
        ctype_filter: '',
        ctype_filter_box : false,
			}
		},
		computed: {
			...mapState(['common'])
		},
		async onLoad() {
      var options = this.$Route.query;

      if(options?.status){
        if(options.status==='1') this.orderTypeIndex = 0;
        if(options.status==='2') this.orderTypeIndex = 1;
        if(options.status==='3') this.orderTypeIndex = 2;
        if(options.status==='0') this.orderTypeIndex = 3;
      }

      this.date_arr = this.$xyfun.getDates(7);
      this.loadData();

		},
		onPullDownRefresh() {

		},
		onReachBottom() {
			if(this.currentPage < this.lastPage) {
				this.currentPage += 1;
				this.loadData();
			}
		},
		methods: {
			//门店及教练列表
			async loadData(){
				var that = this;
				this.$api.post({
					url: '/course_order/lists',
					loadingTip:'加载中...',
					data: {
						page: this.currentPage,
            status: this.orderType[this.orderTypeIndex].type,
            type: this.ctype_filter,
            order: 'starttime',
            date: this.date
					},
					success: res => {
						that.isLoading = false;
						var tempData = res.data;

						this.courseList = [...this.courseList, ...tempData];
						this.isEmpty = !this.courseList.length;
						this.currentPage = res.current_page;
						this.lastPage = res.last_page;
						this.loadStatus = this.currentPage < res.last_page ? 'loadmore' : 'nomore';
					}
				});
			},

      change_crumb(index){
        this.orderTypeIndex = index;
        this.currentPage = 1;
        this.courseList = [];
        this.loadData();
      },

      checkCtype(ctype,ctype_cn){
        this.ctype_filter = ctype;
        this.ctype_cn = ctype_cn;
        this.ctype_filter_box = false;
        this.currentPage = 1;
        this.courseList = [];
        this.loadData();
      },

      InputFocus(e){
        this.date=e.detail.value;
      },
      InputBlur(e){
        this.date=e.detail.value;
        this.currentPage = 1;
        this.lastPage = 1;
        this.courseList=[];
        this.loadData();
      }

		}
	}
</script>

<style>
page {
  background: #f5f5f5;
  padding: 20rpx 0;
}
</style>
<style scoped lang="scss">
.info-box-crumb{
  height: 100rpx;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  font-size: 30rpx;
  view{
    position: relative;
    text-align: center;
    width: 150rpx;
    margin-top: 10rpx;
  }
  .active{
    position: relative;
    text-align: center;
    color: #95e8d0;
    text{
      z-index: 2;
      font-weight: bold;
      position: relative;
    }
    &:after{
      content: '';
      width: 100rpx;
      background: #95e8d0;
      border-radius: 6rpx;
      display: block;
      height: 5rpx;
      left: 0;
      right: 0;
      top: 60rpx;
      margin: 0 auto;
      position: absolute;
    }
  }
}

.search-box{
  display: flex;
  align-items: center;
  padding: 0 30rpx;
  justify-content: space-between;
  margin-top: 20rpx;
  .search{
    position: relative;
    width: 1rpx;
    flex-grow: 1;
    margin-right: 60rpx;
    .yz-iconfont{
      position: absolute;
      left: 30rpx;
      color: #a2a2a2;
      top: 20rpx;
    }
    input{
      background: #fffbfb;
      border-radius: 40rpx;
      font-size: 22rpx;
      padding: 15rpx 20rpx 15rpx 70rpx;
      width: 450rpx;
    }
  }
  .filter{
    font-size: 24rpx;
    display: flex;
    align-items: center;
    position: relative;
    height: 30rpx;
    line-height: 30rpx;
    .yz-iconfont{
      font-size: 18rpx;
    }
    .ctype_box{
      position: absolute;
      z-index: 999;
      top: 40rpx;
      left: -20rpx;
      font-size: 26rpx;
      background: #fff;
      width: 120rpx;
      view{
        padding-left: 20rpx;
        margin-top: 20rpx;
        height: 30rpx;
        line-height: 30rpx;
      }
    }
  }
}

.xy-order-item {
  background: #fff;
  width: 100%;
  .top {
    display: flex;
    font-weight: bold;
    padding-top: 30rpx;
    justify-content: space-between;
    font-size: 26rpx;
    padding-bottom: 10rpx;
    .l {
      .label {
        //background-color: #494444;
        //color: #fff;
        padding: 5rpx 10rpx;
        margin-right: 10rpx;
        border-radius: 5rpx;
      }
    }
  }
  .course {
    margin-top: 30rpx;
    padding-bottom: 30rpx;
    display: flex;
    .l {

      image {
        height: 135rpx;
        width: 202rpx;
      }
    }
    .r {
      margin-left: 20rpx;
      position: relative;
      width: 408rpx;
      .item-text {
        color: #4d4d4d;
      }
    }
  }
  .vip {
    .l {
      height: 135rpx;
      width: 202rpx;
      line-height: 135rpx;
    }
    .r {
      width: 408rpx;
    }
  }

  .price-box {
    bottom: 3rpx;
    width: 100%;
  }

  .goods {
    .item {
      .l {
        width: 178rpx;
        height: 178rpx;
        image {
          width: 178rpx;
        }
      }
      .r {
        width: 432rpx;
      }
      .goods-title {
        max-height: 80rpx;
        overflow: hidden;
      }
    }
  }
}
</style>
